package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAclObjectIdentityByEntriesInheriting", query = "select myAclObjectIdentity from AclObjectIdentity myAclObjectIdentity where myAclObjectIdentity.entriesInheriting = ?1"),
		@NamedQuery(name = "findAclObjectIdentityById", query = "select myAclObjectIdentity from AclObjectIdentity myAclObjectIdentity where myAclObjectIdentity.id = ?1"),
		@NamedQuery(name = "findAclObjectIdentityByObjectIdIdentity", query = "select myAclObjectIdentity from AclObjectIdentity myAclObjectIdentity where myAclObjectIdentity.objectIdIdentity = ?1"),
		@NamedQuery(name = "findAclObjectIdentityByPrimaryKey", query = "select myAclObjectIdentity from AclObjectIdentity myAclObjectIdentity where myAclObjectIdentity.id = ?1"),
		@NamedQuery(name = "findAllAclObjectIdentitys", query = "select myAclObjectIdentity from AclObjectIdentity myAclObjectIdentity") })
@Table(catalog = "sow", name = "acl_object_identity")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "AclObjectIdentity")
@XmlRootElement(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain")
public class AclObjectIdentity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "OBJECT_ID_IDENTITY", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer objectIdIdentity;
	/**
	 */

	@Column(name = "ENTRIES_INHERITING", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Boolean entriesInheriting;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "OWNER_SID", referencedColumnName = "ID") })
	@XmlTransient
	AclSid aclSid;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "PARENT_OBJECT", referencedColumnName = "ID") })
	@XmlTransient
	AclObjectIdentity aclObjectIdentity;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "OBJECT_ID_CLASS", referencedColumnName = "ID", nullable = false) })
	@XmlTransient
	AclClass aclClass;
	/**
	 */
	@OneToMany(mappedBy = "aclObjectIdentity", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<edu.hcmus.sow.domain.AclObjectIdentity> aclObjectIdentities;
	/**
	 */
	@OneToMany(mappedBy = "aclObjectIdentity", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<edu.hcmus.sow.domain.AclEntry> aclEntries;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setObjectIdIdentity(Integer objectIdIdentity) {
		this.objectIdIdentity = objectIdIdentity;
	}

	/**
	 */
	public Integer getObjectIdIdentity() {
		return this.objectIdIdentity;
	}

	/**
	 */
	public void setEntriesInheriting(Boolean entriesInheriting) {
		this.entriesInheriting = entriesInheriting;
	}

	/**
	 */
	public Boolean getEntriesInheriting() {
		return this.entriesInheriting;
	}

	/**
	 */
	public void setAclSid(AclSid aclSid) {
		this.aclSid = aclSid;
	}

	/**
	 */
	@JsonIgnore
	public AclSid getAclSid() {
		return aclSid;
	}

	/**
	 */
	public void setAclObjectIdentity(AclObjectIdentity aclObjectIdentity) {
		this.aclObjectIdentity = aclObjectIdentity;
	}

	/**
	 */
	@JsonIgnore
	public AclObjectIdentity getAclObjectIdentity() {
		return aclObjectIdentity;
	}

	/**
	 */
	public void setAclClass(AclClass aclClass) {
		this.aclClass = aclClass;
	}

	/**
	 */
	@JsonIgnore
	public AclClass getAclClass() {
		return aclClass;
	}

	/**
	 */
	public void setAclObjectIdentities(Set<AclObjectIdentity> aclObjectIdentities) {
		this.aclObjectIdentities = aclObjectIdentities;
	}

	/**
	 */
	@JsonIgnore
	public Set<AclObjectIdentity> getAclObjectIdentities() {
		if (aclObjectIdentities == null) {
			aclObjectIdentities = new java.util.LinkedHashSet<edu.hcmus.sow.domain.AclObjectIdentity>();
		}
		return aclObjectIdentities;
	}

	/**
	 */
	public void setAclEntries(Set<AclEntry> aclEntries) {
		this.aclEntries = aclEntries;
	}

	/**
	 */
	@JsonIgnore
	public Set<AclEntry> getAclEntries() {
		if (aclEntries == null) {
			aclEntries = new java.util.LinkedHashSet<edu.hcmus.sow.domain.AclEntry>();
		}
		return aclEntries;
	}

	/**
	 */
	public AclObjectIdentity() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(AclObjectIdentity that) {
		setId(that.getId());
		setObjectIdIdentity(that.getObjectIdIdentity());
		setEntriesInheriting(that.getEntriesInheriting());
		setAclSid(that.getAclSid());
		setAclObjectIdentity(that.getAclObjectIdentity());
		setAclClass(that.getAclClass());
		setAclObjectIdentities(new java.util.LinkedHashSet<edu.hcmus.sow.domain.AclObjectIdentity>(that.getAclObjectIdentities()));
		setAclEntries(new java.util.LinkedHashSet<edu.hcmus.sow.domain.AclEntry>(that.getAclEntries()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("objectIdIdentity=[").append(objectIdIdentity).append("] ");
		buffer.append("entriesInheriting=[").append(entriesInheriting).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof AclObjectIdentity))
			return false;
		AclObjectIdentity equalCheck = (AclObjectIdentity) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
